package com.bazinga.contact.controller;


import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.classic.Session;

import com.bazinga.contact.model.StudentSkills;
import com.bazinga.contact.util.HibernateUtil;


public class StudentSkillsManager extends HibernateUtil {

	public StudentSkills add(StudentSkills studentSkills) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		session.save(studentSkills);
		session.getTransaction().commit();
		return studentSkills;
	}
	public StudentSkills delete(Long id) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		StudentSkills studentSkills = (StudentSkills) session.load(StudentSkills.class, id);
		if(null != studentSkills) {
			session.delete(studentSkills);
		}
		session.getTransaction().commit();
		return studentSkills;
	}

	public List<StudentSkills> list() {
		
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		List<StudentSkills> studentSkills = null;
		try {
			
			studentSkills = (List<StudentSkills>)session.createQuery("from StudentSkills").list();
			
		} catch (HibernateException e) {
			e.printStackTrace();
			session.getTransaction().rollback();
		}
		session.getTransaction().commit();
		return studentSkills;
	}
}
